package xyz.scootaloo.oj.offer

import org.junit.Test
import xyz.scootaloo.console.app.support.Tester

/**
 * @author flutterdash@qq.com
 * @since 2021/4/13 9:29
 */
class P57I {

    private fun twoSum(nums: IntArray, target: Int): IntArray {
        val size = nums.size - 1
        for (i in 0 until size) {
            val current = nums[i]
            val need = target - current
            val res = nums.binarySearch(need, i + 1, size + 1)
            if (res > 0) {
                return intArrayOf(current, need)
            }
        }

        return IntArray(0)
    }

    @Test
    fun test0() {
        val input1 = intArrayOf(2, 7, 11, 15)
        println(twoSum(input1, 9).contentToString())
        val input2 = intArrayOf(10, 26, 30, 31, 47, 60)
        println(twoSum(input2, 40).contentToString())
        val input3 = intArrayOf(14, 15, 16, 22, 53, 60)
        println(twoSum(input3, 76).contentToString())
    }

}
